﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace VOL.SmartHealthcare.Infrastructure
{
    public interface IBaseRepository<T>where T : class
    {
        /// <summary>
        /// 新增实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>返回受影响行数</returns>
        Task<int> AddAsync(T entity);
        /// <summary>
        /// 批量新增实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>返回受影响行数</returns>
        Task<int> AddRangeAsync(List<T> entity);
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <returns>返回数据集</returns>
        IQueryable<T> GetAll();
        /// <summary>
        /// 有条件的查询数据
        /// </summary>
        /// <param name="expression">查询参数</param>
        /// <returns>返回数据集</returns>
        IQueryable<T> GetAll(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 通过主键查询一条数据
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>返回一条数据</returns>
        Task<T> FindAsync(int id);
        /// <summary>
        /// 有条件的返回一条数据
        /// </summary>
        /// <param name="expression">查询条件</param>
        /// <returns>返回受影响行数</returns>
        Task<T> FindAsync(Expression<Func<T, bool>> expression);
        /// <summary>
        /// 修改用户实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> UpdateAsync(T entity);
        /// <summary>
        /// 批量修改用户实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> UpdateRangeAsync(List<T> entity);
        /// <summary>
        /// 删除单条数据
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>返回受影响行数</returns>
        Task<int> DeleteAsync(int id);
        /// <summary>
        /// 有条件删除单条数据
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>返回受影响行数</returns>
        Task<int> DeleteAsync(Expression<Func<T, bool>> expression);
        /// <summary>
        /// 批量删除数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> DeletteRangeAsync(Expression<Func<T, bool>> expression);
    }
}
